package com.study.mysql.readwriteseparation1.route;

import com.study.mysql.readwriteseparation1.constant.ClientDataSource;

import java.util.Objects;

public class ClientDataSourceContextHolder {

    private static final ThreadLocal<ClientDataSource> CONTEXT = new ThreadLocal<>();

    public static void set(ClientDataSource clientDataSource) {
        CONTEXT.set(Objects.requireNonNull(clientDataSource, "clientDatabase cannot be null"));
    }

    public static ClientDataSource getClientDatabase() {
        return CONTEXT.get();
    }

    public static void clear() {
        CONTEXT.remove();
    }
}
